package com.zhx.business.rpc;

import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import com.zhx.business.api.ProductRpc;
import com.zhx.business.entity.Product;
import com.zhx.business.repository.dto.ProductCondition;
import com.zhx.business.repository.spec.ProductSpec;
import com.zhx.business.result.RpcResponseEntity;
import com.zhx.business.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * product rpc 实现服务类
 */
@Slf4j
@AutoJsonRpcServiceImpl
@Service
public class ProductRpcImpl implements ProductRpc {
    @Autowired
    private ProductService productService;

    @Override
    public ResponseEntity list(ProductCondition condition, Pageable pageable) {
        log.debug("进入rpc list查询方法,请求:{}",condition);

        Page<Product> all = productService.findAll(new ProductSpec(condition), pageable);
        return ResponseEntity.ok(all);
    }

    @Override
    public Product findOne(String uid) {
        log.debug("进入rpc findOne查询方法,请求:{}",uid);
        Product one = productService.findOne(uid);
        return one;
    }
}
